package com.sphd.beautysalon.model;


import com.android.volley.VolleyError;
import com.sphd.beautysalon.info.DataNoInfo;
import com.sphd.beautysalon.info.InorOutRecordInfo;
import com.sphd.beautysalon.presenter.DateQueryPresenterImpl;
import com.sphd.beautysalon.interfaces.VolleyJsonObjectCallBack;
import com.wzh.frame.utils.JsonUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
 * Created by Hu on 2016/12/27
 */

public class DateQueryModelImpl implements DateQueryModel {

    @Override
    public void sendUrl(String url, DateQueryPresenterImpl dateQueryPresenter) {
        volleyUtil.setJsonObjectRequest(url, new VolleyJsonObjectCallBack() {
            @Override
            public void onResponse(JSONObject response) {
                try {
                    DataNoInfo dataNoInfo = JsonUtil.getObjectFromString(response.getString("listsum"), DataNoInfo.class);
                    List<InorOutRecordInfo> goodInOrOutInfos = JsonUtil.getListFromString(response.getString("list"), InorOutRecordInfo.class);
                    dateQueryPresenter.sendRes(dataNoInfo,goodInOrOutInfos);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onErrorResponse(VolleyError error) {
                dateQueryPresenter.sendError(error);
            }
        });
    }
}